import request from '@/utils/request'
import url from './url'

export function login(data) {
  return request({
    url: url.login,
    method: 'post',
    data,
    showMsg: false
  })
}

export function getInfo() {
  return request({
    url: url.getCurrentUser,
    method: 'get'
  })
}

// 用户列表
export function getUserList(params) {
  //   current,
  // size,
  // userName

  return request({
    url: url.userGetPage,
    method: 'get',
    params
  })
}

// 删除用户
export function delUser(code) {
  return request({
    url: url.userDel,
    params: { code },
    method: 'post'
  })
}
// 重置用户
export function resetUser(code) {
  return request({
    url: url.userRest,
    method: 'post',
    params: { code },
  })
}

// 新增/修改用户
export function editUser(data = {}) {
  const { code } = data
  const apiUrl = code ? url.userMod : url.userAdd
  return request({
    url: apiUrl,
    method: 'post',
    data
  })
}

// 更新用户密码
export function updatePwd(data) {
  return request({
    url: url.updatePwd,
    data,
    method: 'post',
    params: data,
  })
}

export function logout() {
  return request({
    url: '/vue-admin-template/user/logout',
    method: 'post'
  })
}
